
import { SearchOutlined } from '@ant-design/icons';
import { Button, Input, Space, Table } from 'antd';
import Highlighter from 'react-highlight-words';
import React from "react";
import axios from "axios";
axios.defaults.timeout= 26000;



class Cnckb extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      a: [],
      b: [],
      c: [],
      d: [],
      e: [],
      f: [],
      g: [],
      h: [],
      i: [],
      j: [],
      k1: [],
      a12:[],
      a13:[],
      a14:[],
      a15:[],
      a16:[],
      a17:[],
      a1:[],
      a18:[],
      a19:[],
      a20:[],
      a21:[],
      a31:[],
      a22:[],
      a23:[],
      a24:[],
      a25:[],
      a36:[],
      a37:[],
      a38:[],
      a39:[],
      a40:[],
      usc:[],
      uac:[],
      uzc:[],
      searchText:"",
      searchedColumn:"",

    };
    this.searchInput= React.createRef(null)
  }
  
  
  /* 
  a= 蔡正平= 43.153.65.89
  b= 郭发展=  43.153.79.98
  c = 郭蒋平= 43.135.172.133
  d  = 郭凯鸿6=43.152.217.89
  e=  郭煜尚7= 43.158.210.229
  f= 李瑶瑶2= 43.158.194.253
  g=  潘秀丽1= 43.134.231.239
  h=    彭香兰8=  43.135.155.149
  i= 叶凤华3=43.156.231.195
  j= 沈信义5=119.28.250.113
  k=刘爱绿4=119.28.250.113
  */
  componentDidMount() {
   // 账号1的高度a
 axios
      .get("http://43.153.65.89:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          a: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ a: "0" });
      })
      //账号2高度b
    axios
      .get("http://43.153.8.136:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          b: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ b: "0" });
      });
         //账号3高度c
    axios
      .get("http://43.153.15.197:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          c: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ c: "0" });
      });
         //账号4高度d
    axios
      .get("http://43.135.180.56:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          d: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ d: "0" });
      });
         //账号5高度e
    axios
      .get("http://43.135.162.210:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          e: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ e: "0" });
      });
         //账号6高度f
    axios
      .get("http://43.153.49.20:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          f: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ f: "0" });
      });
         //账号7高度g
    axios
      .get("http://43.153.117.44:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          g: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ g: "0" });
      });
         //账号8高度h
    axios
      .get("http://43.153.55.221:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          h: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ h: "0" });
      });
         //账号9高度i
    axios
      .get("http://129.226.214.155:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          i: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ i: "0" });
      });
      //  获取uuid
    axios
    .get("/node-selection-stats?uuid=a62ac00a-e326-44be-bab1-a82dd8da37d4")
        .then((res) => {
          console.log(res.data.core_latest_ledger);
          this.setState({
            uac: JSON.stringify(res.data.stats.date_added),
            usc: JSON.stringify(res.data.stats.user_start_date),
    
          });
            this.setState({
              uzc: JSON.stringify(res.data.stats.availability),
    
            });
    
        })
        .catch((err) => {
          this.setState({ uac: "无效uuid号" });
        });
         //账号10高度j
    axios
      .get("http://43.159.47.159:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          j: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ j: "0" });
      });
        //账号11高度k
    axios
    .get("http://43.153.62.208:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        k1: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ k1: "0" });
    });
     
     //账号12高度a12
     axios
     .get("http://43.134.166.106:31401")
     .then((res) => {
       console.log(res.data.core_latest_ledger);
       this.setState({
         a12: res.data.core_latest_ledger,
       });
     })
     .catch((err) => {
       this.setState({ a12: "0" });
     });
      //账号13高度a13
    axios
    .get("http://43.153.69.17:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        a13: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ a13: "0" });
    });
     //账号13高度a14
     axios
     .get("http://43.153.92.177:31401")
     .then((res) => {
       console.log(res.data.core_latest_ledger);
       this.setState({
         a14: res.data.core_latest_ledger,
       });
     })
     .catch((err) => {
       this.setState({ a14: "0" });
     });
      //账号13高度a15
    axios
    .get("http://43.134.88.192:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        a15: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ a15: "0" });
    });
     //账号13高度a16
     axios
     .get("http://43.135.158.203:31401")
     .then((res) => {
       console.log(res.data.core_latest_ledger);
       this.setState({
         a16: res.data.core_latest_ledger,
       });
     })
     .catch((err) => {
       this.setState({ a16: "0" });
     });
      //账号13高度a17
    axios
    .get("http://43.153.99.250:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        a17: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ a17: "0" });
    });
     //账号13高度a18
     axios
     .get("http://43.134.237.87:31401")
     .then((res) => {
       console.log(res.data.core_latest_ledger);
       this.setState({
         a18: res.data.core_latest_ledger,
       });
     })
     .catch((err) => {
       this.setState({ a18: "0" });
     });
      //账号13高度a19
    axios
    .get("http://43.135.166.224:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        a19: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ a19: "0" });
    });
     //账号13高度a20
     axios
     .get("http://43.153.41.102:31401")
     .then((res) => {
       console.log(res.data.core_latest_ledger);
       this.setState({
         a20: res.data.core_latest_ledger,
       });
     })
     .catch((err) => {
       this.setState({ a20: "0" });
     });
      //账号13高度a21
    axios
    .get("http://43.153.19.30:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        a21: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ a21: "0" });
    });
     //账号13高度a22
     axios
     .get("http://43.153.66.45:31401")
     .then((res) => {
       console.log(res.data.core_latest_ledger);
       this.setState({
         a22: res.data.core_latest_ledger,
       });
     })
     .catch((err) => {
       this.setState({ a22: "0" });
     });
      //账号13高度a23
    axios
    .get("http://43.153.59.36:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        a23: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ a23: "0" });
    });
    //  //账号13高度a25
    //  axios
    //  .get("http://43.152.217.161:31401")
    //  .then((res) => {
    //    console.log(res.data.core_latest_ledger);
    //    this.setState({
    //      a13: res.data.core_latest_ledger,
    //    });
    //  })
    //  .catch((err) => {
    //    this.setState({ a13: "0" });
    //  });

  }
  render() {
    const handleSearch = (selectedKeys, confirm, dataIndex) => {
      confirm();
      this.setState({searchText:selectedKeys[0]});
      this.setState({searchedColumn:dataIndex});
    }
    const handleReset = (clearFilters) => {
      clearFilters();
      this.setState({searchText:""});
    };
    const getColumnSearchProps = (dataIndex) => ({
      filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }) => (
        <div
          style={{
            padding: 8,
          }}
          onKeyDown={(e) => e.stopPropagation()}
        >
          <Input
            ref={this.searchInput}
            placeholder={`Search ${dataIndex}`}
            value={selectedKeys[0]}
            onChange={(e) => setSelectedKeys(e.target.value ? [e.target.value] : [])}
            onPressEnter={() => handleSearch(selectedKeys, confirm, dataIndex)}
            style={{
              marginBottom: 8,
              display: 'block',
            }}
          />
          <Space>
            <Button
              type="primary"
              onClick={() => handleSearch(selectedKeys, confirm, dataIndex)}
              icon={<SearchOutlined />}
              size="small"
              style={{
                width: 90,
              }}
            >
             搜索
            </Button>
            <Button
              onClick={() => clearFilters && handleReset(clearFilters)}
              size="small"
              style={{
                width: 90,
              }}
            >
             重置
            </Button>
            <Button
              type="link"
              size="small"
              onClick={() => {
                confirm({
                  closeDropdown: false,
                });
                this.setState({searchText:selectedKeys[0]});
               this.setState({searchedColumn:dataIndex});
               
              }}
            >
            恢复
            </Button>
            <Button
              type="link"
              size="small"
              onClick={() => {
                close();
              }}
            >
             关闭
            </Button>
          </Space>
        </div>
      ),
      filterIcon: (filtered) => (
        <SearchOutlined
          style={{
            color: filtered ? '#1677ff' : undefined,
          }}
        />
      ),
      onFilter: (value, record) =>
        record[dataIndex].toString().toLowerCase().includes(value.toLowerCase()),
      onFilterDropdownOpenChange: (visible) => {
        if (visible) {
          setTimeout(() => this.searchInput.current?.select(), 100);
        }
      },
      render: (text) =>
        this.state.searchedColumn === dataIndex ? (
          <Highlighter
            highlightStyle={{
              backgroundColor: '#ffc069',
              padding: 0,
            }}
            searchWords={[this.state.searchText]}
            autoEscape
            textToHighlight={text ? text.toString() : ''}
          />
        ) : (
          text
        ),
    });

    const dataSource = [
     
      
      
      
      
     
      {
        key: '2',
        name:  '苏银满（斌哥）',
       address: this.state.a15,
       differ: this.state.a-this.state.a15,
       todesk:'399 475 163',
       ip:<a href='http://43.134.88.192:31401' target="_blank">43.153.97.38 192.168.10.53</a>, 
        des: '云服务器新加坡',
      },
      {
        key: '3',
        name:  '王秋山（斌哥）',
       address: this.state.a16,
       differ: this.state.a-this.state.a16,
       todesk:'534 512 840',
       ip:<a href='http://43.135.158.203:31401' target="_blank">43.153.25.155 192.168.10.55</a>, 
        des: '云服务器美国',
      },
     
      
      {
        key: '4',
        name:  '杨林香（斌哥）',
       address: this.state.a19,
       differ: this.state.a-this.state.a19,
       todesk:'811 906 459',
       ip:<a href='http://43.135.166.224:31401' target="_blank">43.153.27.94 192.168.10.56</a>, 
        des: '云服务器美国',
      },
      {
        key: '5',
        name:  '余兴容（斌哥）',
       address: this.state.a20,
       differ: this.state.a-this.state.a20,
       todesk:'127 824 715',
       ip:<a href='http://43.153.41.102:31401' target="_blank">43.51.199.103 192.168.10.51</a>, 
        des: '云服务器美国'
      },
      {
        key: '6',
        name:  '郑志龙（斌哥）',
       address: this.state.a21,
       differ: this.state.a-this.state.a21,
       todesk:'898 926 071',
       ip:<a href='http://43.153.19.30:31401' target="_blank">43.153.68.127 192.168.10.51</a>, 
        des: '云服务器美国',
      },
      {
        key: '7',
        name:  '陈定怒（斌哥）',
       address: this.state.a22,
       differ: this.state.a-this.state.a22,
       todesk:'672 612 123',
       ip:<a href='http://43.153.66.45:31401' target="_blank">170.106.82.223  192.168.10.54</a>, 
        des: '云服务器美国',
      },
      {
        key: '8',
        name:  '林贤园（斌哥）',
       address: this.state.a23,
       differ: this.state.a-this.state.a23,
       todesk:'485 314 879',
       ip:<a href='http://43.153.59.36:31401' target="_blank">43.153.97.38 192.168.10.52</a>, 
        des: '云服务器美国',
      },
      {
        key: '1',
        name:  '陈克斌(斌哥家)',
       address: this.state.c,
       differ: this.state.a-this.state.c,
       todesk:'125 986 328',
       ip:<a href='http://43.153.15.197:31401' target="_blank">43.159.138.243 192.168.10.52</a>, 
        des: '云服务器美国',
      },
      {
        key: '45',
        name:  '陈睿(斌哥家)',
       address: this.state.e,
       differ: this.state.a-this.state.e,
       todesk:'792 183 339',
       ip:<a href='http://43.135.162.210:31401' target="_blank">43.153.31.243 192.168.10.56</a>, 
        des: '云服务器美国',
      },


       {
        key: '46',
        name:  '陈少林(业主)',
       address: this.state.f,
       differ: this.state.a-this.state.f,
       todesk:'325 786 479',
       ip:<a href='http://43.153.49.20:31401' target="_blank">43.153.90.179 192.168.10.52</a>, 
        des: '云服务器美国',
      },
      {
        key: '47',
        name:  '陈同帮（业主)',
       address: this.state.g,
       differ: this.state.a-this.state.g,
       todesk:'805 615 726',
       ip:<a href='http://43.153.117.44:31401' target="_blank">43.134.166.140 192.168.10.57</a>, 
        des: '云服务器美国',
      },
     
      {
        key: '49',
        name:  '甘 （业主）',
       address: this.state.i,
       differ: this.state.a-this.state.i,
       todesk:'861 002 525',
       ip:<a href='http://129.226.214.155:31401' target="_blank">129.226.214.155</a>, 
       
       uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=a62ac00a-e326-44be-bab1-a82dd8da37d4" target="_blank">
ec2b1ac8-347a-465d-8ae2-4a4e71c240ed
          </a>
          
        ),
        stt: this.state.usc,
        add: this.state.uac,
       
zxl: this.state.uzc*100,
        des: '云服务器新加坡',
      },
      {
        key: '50',
        name:  '韩宏取(业主)',
       address: this.state.j,
       differ: this.state.a-this.state.j,
       todesk:'881 980 965',
       ip:<a href='http://43.159.47.159:31401' target="_blank">170.106.82.223  192.168.10.55</a>, 
        des: '云服务器新加坡',
      },
      
      {
        key: '51',
        name:  '胡忠海 (业主)',
       address: this.state.a12,
       differ: this.state.a-this.state.a12,
       todesk:'776 281 764',
       ip:<a href='http://43.134.166.106:31401' target="_blank">43.153.17.139 192.168.10.52</a>, 
        des: '云服务器新加坡',
      },
      
      // {
      //   key: '1',
      //   name:  '蔡元华',
      //  address: this.state.a,
      //  differ: this.state.a-this.state.a,
      //   des: '云服务器美国',
      // },
      // {
      //   key: '1',
      //   name:  '蔡元华',
      //  address: this.state.a,
      //  differ: this.state.a-this.state.a,
      //   des: '云服务器美国',
      // },
    ];
  
    const columns = [
      {
        title: '业主名字',
        dataIndex: 'name',
        key: 'name',
        ...getColumnSearchProps('name'),
      },
      {
        title: '区块高度',
        dataIndex: 'address',
        key: 'address',
      },
      {
        title: '区块延迟数值',
        dataIndex: 'differ',
        key: 'differ',
        sorter: {
          compare: (a, b) => a.differ - b.differ,
          multiple: 3,
        },
      },
      
      {
        title: "todesk",
        dataIndex: "todesk",
        key: "todesk",
        ...getColumnSearchProps('todesk'),
      },
      {
        title: '云服务器ip地址',
        dataIndex: 'ip',
        key: 'ip',
      }
      ,
      {
        title: "uuid",
        dataIndex: "uuid",
        key: "uuid",
      },
      {
        title: "开始时间",
        dataIndex: "stt",
        key: "stt",
      },
      {
        title: "最后一次时间",
        dataIndex: "add",
        key: "add",
      },
      {
        title: "在线率百分之",
        dataIndex: "zxl",
        key: "zxl",
      },
      {
        title: '云服务器地区',
        dataIndex: 'des',
        key: 'des',
      },
    ];
    return (
      <div>
            
        <center>
       
          <font size='18' color = "red" >苍南陈克斌14台节点区块高度</font> 
        <Table dataSource={dataSource} columns={columns} />;
  
        </center>
      </div>
    );
  }
}

export default Cnckb;

